//
//  LOLbigGodTableViewCell.m
//  LOLXXbox
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLbigGodTableViewCell.h"
#import "LOLBaseCollectionView.h"
#define WIDTH [[UIScreen mainScreen]bounds].size.width
#import "LOLGOODCollectionViewCell.h"
#import "LOLFitCellHeight.h"
#define HEIGHT [[UIScreen mainScreen]bounds].size.height
#define PADDING5 WIDTH/75
#define SKILLIMAGEURL(hero,skill) [NSString stringWithFormat:@"http://img.lolbox.duowan.com/abilities/%@_%@_64x64.png",hero,skill]
#define EQUIPIMAGEURL(name) [NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",name]
#define EQUIPIMAGEURL(name) [NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",name]
#import <UIImageView+WebCache.h>

@implementation LOLbigGodTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setEquipIdArr:(NSArray *)equipIdArr
{

    _equipIdArr = equipIdArr;
    
    [self.collectionV reloadData];

    
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createView];
    }
    return self;
    
}
-(void)createView
{
    
    self.gameTime=[[UILabel alloc]init];
    [self.contentView addSubview:self.gameTime];

    
    
    self.collectionV=[[LOLBaseCollectionView alloc]initWithFrame:CGRectZero flowLayoutItemSize:CGSizeMake((WIDTH-35)/6,(WIDTH-35)/6) xSpace:5 ySpace:0 sectionInSet:UIEdgeInsetsMake(5, 5, 5, 5) cell:[LOLGOODCollectionViewCell class] reuse:@"cCellReuse"];
    self.collectionV.delegate=self;
    self.collectionV.dataSource=self;
    [self.contentView addSubview:self.collectionV];

    
    self.heroIntroduceLabel=[[UILabel alloc]init];
    self.heroIntroduceLabel.numberOfLines=0;
    [self.heroIntroduceLabel sizeToFit];
    self.heroIntroduceLabel.font=[UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.heroIntroduceLabel];
   
    
    
    
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.gameTime.frame=CGRectMake(5, 8, WIDTH-10, HEIGHT/3.2/7);
    self.collectionV.frame=CGRectMake(0, CGRectGetMaxY(self.gameTime.frame), WIDTH,[LOLFitCellHeight computeCollectionViewNumData:self.skillIdArr.count+self.equipIdArr.count ItemHeight:(WIDTH-35)/6+10 numOflines:6]);
    
    [LOLFitCellHeight computeLabelCellLabel:self.heroIntroduceLabel fontSize:15 frame:CGRectMake(5, CGRectGetMaxY(self.collectionV.frame)+PADDING5, WIDTH-10, 0)];
    
    
    
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.skillIdArr.count+self.equipIdArr.count;
    
    
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LOLGOODCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cCellReuse" forIndexPath:indexPath];
    
    
    
    if(indexPath.row<6&&self.skillIdArr)
    {
        cell.idLabel.backgroundColor=[UIColor colorWithWhite:1.000 alpha:0.670];
        cell.idLabel.text=self.skillIdArr[indexPath.row];
        [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:SKILLIMAGEURL(self.en_name, self.skillIdArr[indexPath.row])] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        
    }
    
    else if (!self.skillIdArr) {
        
        [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:EQUIPIMAGEURL(self.equipIdArr[indexPath.row])] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        cell.idLabel.backgroundColor=[UIColor clearColor];
        cell.idLabel.text = @"";
    }
    
    else if(indexPath.row>5)
    {
        [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:EQUIPIMAGEURL(self.equipIdArr[indexPath.row-6])] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        cell.idLabel.backgroundColor=[UIColor clearColor];
        cell.idLabel.text = @"";
        
    }
    
    
    return cell;
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *typeId =@"";
    NSString *skillId=@"";
    if(indexPath.row<6&&self.skillIdArr)
    {
        skillId=[[self.en_name stringByAppendingString:@"_"] stringByAppendingString:self.skillIdArr[indexPath.row]];
        
        
    }
    
    else if (!self.skillIdArr) {
        typeId=self.equipIdArr[indexPath.row];
        
    }
    
    else if(indexPath.row>5)
    {
        typeId=self.equipIdArr[indexPath.row-6];
        
    }
    
    if ([self.delegate respondsToSelector:@selector(pushToDetailPage:skillId:)]) {
        [self.delegate pushToDetailPage:typeId skillId:skillId];
    }
    
    
    
    
    
}


@end
